using AndyPike.Unfuddle.Contracts;
using AndyPike.Unfuddle.Entities.Projects;

namespace AndyPike.Unfuddle.Commands.Projects
{
    /// <summary>
    /// Provides a command for deleting an existing project from the Unfuddle server
    /// </summary>
    public class DeleteProject : IUnfuddleChangeCommand
    {
        private readonly int projectId;

        /// <summary>
        /// Instantiates the DeleteProject command
        /// </summary>
        /// <param name="projectId">The id of the existing project to delete</param>
        public DeleteProject(int projectId)
        {
            GuardAgainst.ArgumentOutsideRange(projectId, "projectId", 1, int.MaxValue);

            this.projectId = projectId;
        }

        /// <summary>
        /// Deletes an existing project from the Unfuddle server
        /// </summary>
        /// <param name="service">The Unfuddle service to use when executing the command</param>
        public void Execute(IUnfuddleService service)
        {
            GuardAgainst.ArgumentNull(service, "service");

            string url = service.BuildUrl("projects/{0}", projectId);
            service.InvokeRequest<Project>(url, HttpMethod.DELETE, null);
        }
    }
}